package com.xq.spring.postprocess.bean;

import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import com.xq.spring.beans.Person;

/**
 * 基础的BeanFactory容器测试类.
 * @author 郭凯强
 */
public class BaseBeanFactory {
	public static void main(String[] args) {
		//创建加载XML配置文件的Resource
		Resource cfgResource=new ClassPathResource("cfg-postprocess-bean.xml");
		//创建默认的BeanFactory
		DefaultListableBeanFactory beanFactory=new DefaultListableBeanFactory();
		//让默认的BeanFactory加载XML配置文件
		new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(cfgResource);
		//注册Bean后处理器
		/*BeanPostProcessor beanPp=(BeanPostProcessor) beanFactory.getBean("beanPp");
		beanFactory.addBeanPostProcessor(beanPp);*/
		beanFactory.addBeanPostProcessor(beanFactory.getBean(CustomBeanPostProcessor.class));
		//获取Bean
		Person chinese=beanFactory.getBean("chinese",Person.class);
		chinese.useAxe();
	}
}
